<?php
class ZipcodeModel extends CI_Model {
	function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function getByZipcode($zipcode){
		$query = $this->db->get_where('zipcode', array('ZipCode' =>$zipcode));
		$zipcodeData = $query->result();
		if(count($zipcodeData) > 0){
			return $zipcodeData[0];
		}else{
			return null;
		}
    }
    function getByCity($city){
		$query = $this->db->like('City', $city)->get('zipcode');
		$zipcodeData = $query->result();
		if(count($zipcodeData) > 0){
			return $zipcodeData[0];
		}else{
			return null;
		}
    }
    function getByCityAndState($city, $state){
		$this->db->where("(State = '" . $state ."' OR StateFullName='".$state."')");
		$this->db->like('City', $city);
		$query = $this->db->get('zipcode');
		$zipcodeData = $query->result();
		if(count($zipcodeData) > 0){
			return $zipcodeData[0];
		}else{
			return null;
		}
    }    
}